package com.android.miniProject;

import java.util.List;
import java.util.Vector;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.Overlay;

public class VisualisationTrajetActivity extends MapActivity{

	MapView mapView;
	MapController mapController;
	//GeoPoint geoPoint1;//,geoPoint2;
	
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.visualisation_trajet_layout);
        mapView = (MapView) findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);				// Activation des boutons pour le zoom
        
        mapController = mapView.getController();
    	
        if(RunActivity.serviceBinder.geoPointsVector.size()!=0){
        	this.drawPath(RunActivity.serviceBinder.geoPointsVector, Color.RED);
        

        mapController.animateTo(RunActivity.serviceBinder.geoPointsVector.elementAt(0));}
        mapController.setZoom(13);
        mapView.invalidate();
        
     // Click Listener
        OnClickListener clickListener = new OnClickListener()
        {
          @Override
          public void onClick(View actualView)
          {
        	  switch(actualView.getId()){
        	    
    	  	// Boutons du menu
    	  	case R.id.button1 :       	  
    	  		// Navigation to runActivity
    	  		Intent runIntent = new Intent(actualView.getContext(), RunActivity.class);
    	  		startActivity(runIntent);
    	  		break;
    	  	case R.id.button2 : 
    	  		// Navigation to TrainingActivity
    	  		Intent trainingIntent = new Intent(actualView.getContext(), TrainingActivity.class);
    	  		startActivity(trainingIntent);
    	  		break;
    	  	case R.id.button3:
    	  		Intent analyseIntent = new Intent(actualView.getContext(),AnalyseActivity.class);
    	  		startActivity(analyseIntent);
    	  		break;
    	  		
    	  	case R.id.button4 : 
    	  	// Navigation to ServicesDemo (MUSIC in background : see services)
    	  		Intent musicIntent = new Intent(actualView.getContext(),ServicesMusic.class);
    	  		startActivity(musicIntent);
    	  		break;
        	  	
        	  }
          }
       };
       
       Button newRun = (Button) findViewById(R.id.button1);
       newRun.setOnClickListener(clickListener);
       
       Button trainings = (Button) findViewById(R.id.button2);
       trainings.setOnClickListener(clickListener);
       
       Button post_run = (Button) findViewById(R.id.button3);
       post_run.setOnClickListener(clickListener);
       
       Button settings = (Button) findViewById(R.id.button4);
       settings.setOnClickListener(clickListener);
        
    }
	
	public void drawPath(Vector<GeoPoint> vec, int color){
		List<Overlay> overlayList = mapView.getOverlays();
		for(int i=0;i<vec.size()-1;i++){
			overlayList.add(new PathOverlay(vec.elementAt(i),vec.elementAt(i+1),color));
		}
	}

	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}
}
